import { defineStore } from 'pinia';
import { ImageCitationInfo } from '@p/main-windowObject';

interface Returns {
	imageCitationInfo?: ImageCitationInfo;
}

export const useMode5Store = defineStore('mode5', {
	state(): Returns {
		return {
			imageCitationInfo: undefined,
		};
	},
	actions: {
		setImageCitationInfo(value: ImageCitationInfo | undefined) {
			this.imageCitationInfo = value;
		},
		removeDirInfoImageItem(path: string) {
			if (this.imageCitationInfo) {
				for (let i = 0; i < this.imageCitationInfo.dirInfo.length; i++) {
					let s = false;
					for (let j = 0; j < this.imageCitationInfo.dirInfo[i].citationInfo.length; j++) {
						if (this.imageCitationInfo.dirInfo[i].citationInfo[j].fullPath === path) {
							s = true;

							this.imageCitationInfo.dirInfo[i].citationInfo.splice(j, 1);

							break;
						}
					}

					if (s) break;
				}

				this.imageCitationInfo.mdInfo.forEach((t1, i1) => {
					t1.dirInfo.forEach((t2, i2) => {
						t2.citationInfo.forEach((t3, i3) => {
							if (t3.fullPath === path) {
								this.imageCitationInfo?.mdInfo[i1].dirInfo[i2].citationInfo.splice(i3, 1);
							}
						});
					});
				});
			}
		},
	},
});
